home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / insuranc.swf / scripts / __Packages / Sounds.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  3.3 KB  |  114 lines

  1. class Sounds
  2. {
  3.    static var mainSounds;
  4.    static var mcSoundsHolder;
  5.    static var soundsList;
  6.    static var randomSoundNamesList;
  7.    static var ambienceInterval;
  8.    function Sounds()
  9.    {
  10.    }
  11.    static function setSounds(Void)
  12.    {
  13.       if(Sounds.mainSounds == undefined)
  14.       {
  15.          Sounds.mainSounds = new Sound(_root);
  16.          Sounds.mcSoundsHolder = _root.createEmptyMovieClip("mcSoundsHolder",_root.getNextHighestDepth());
  17.          Sounds.init();
  18.          Sounds.mainSoundUp();
  19.          Sounds.playSound("gameMusic",99999);
  20.          Sounds.setVolume("gameMusic",70);
  21.       }
  22.    }
  23.    static function mainSoundUp(Void)
  24.    {
  25.       _root.mcSoundBtn.gotoAndStop("up");
  26.       _root.mcSoundBtn.btnSound.onRelease = Sounds.mainSoundMedium;
  27.       Sounds.mainSounds.setVolume(100);
  28.       Sounds.playSound("gameMusic",99999);
  29.    }
  30.    static function mainSoundMedium(Void)
  31.    {
  32.       _root.mcSoundBtn.gotoAndStop("medium");
  33.       _root.mcSoundBtn.btnSound.onRelease = Sounds.mainSoundDown;
  34.       Sounds.stopSound("gameMusic");
  35.    }
  36.    static function mainSoundDown(Void)
  37.    {
  38.       _root.mcSoundBtn.gotoAndStop("down");
  39.       _root.mcSoundBtn.btnSound.onRelease = Sounds.mainSoundUp;
  40.       Sounds.mainSounds.setVolume(0);
  41.    }
  42.    static function init(Void)
  43.    {
  44.       var _loc4_ = new Array("skid","vapourise","tyrescreech","carCrash","gameMusic","splash","engineIdle");
  45.       Sounds.soundsList = new Object();
  46.       var _loc5_ = _loc4_.length;
  47.       var _loc1_ = 0;
  48.       while(_loc1_ < _loc5_)
  49.       {
  50.          var _loc2_ = _loc4_[_loc1_];
  51.          var _loc3_ = Sounds.mcSoundsHolder.createEmptyMovieClip("holder" + _loc1_,_loc1_);
  52.          Sounds.soundsList[_loc2_] = new Sound(_loc3_);
  53.          Sounds.soundsList[_loc2_].attachSound(_loc2_);
  54.          _loc1_ = _loc1_ + 1;
  55.       }
  56.       Sounds.setVolume("splash",250);
  57.       Sounds.setVolume("engineIdle",250);
  58.    }
  59.    static function playSound(name, loops)
  60.    {
  61.       if(loops == undefined)
  62.       {
  63.          loops = 0;
  64.       }
  65.       Sounds.soundsList[name].start(0,loops);
  66.    }
  67.    static function stopSound(name)
  68.    {
  69.       Sounds.soundsList[name].stop();
  70.    }
  71.    static function stopAllSounds(Void)
  72.    {
  73.       for(var _loc1_ in Sounds.soundsList)
  74.       {
  75.       }
  76.    }
  77.    static function setVolume(name, volume)
  78.    {
  79.       Sounds.soundsList[name].setVolume(volume);
  80.    }
  81.    static function getVolume(name)
  82.    {
  83.       return Sounds.soundsList[name].getVolume();
  84.    }
  85.    static function playAmbience(Void)
  86.    {
  87.       var _loc2_ = Sounds.randomSoundNamesList.length;
  88.       var _loc3_ = Math.floor(_loc2_ * Math.random());
  89.       var _loc1_ = Sounds.randomSoundNamesList[_loc3_];
  90.       var _loc4_ = 20 + Math.floor(30 * Math.random());
  91.       Sounds.setVolume(_loc1_,_loc4_);
  92.       Sounds.playSound(_loc1_,0);
  93.       Sounds.stopAmbience();
  94.       Sounds.startAmbience();
  95.    }
  96.    static function startAmbience(bFirst)
  97.    {
  98.       var _loc1_ = undefined;
  99.       if(bFirst)
  100.       {
  101.          _loc1_ = 2000 + Math.round(3000 * Math.random());
  102.       }
  103.       else
  104.       {
  105.          _loc1_ = 10000 + Math.round(10000 * Math.random());
  106.       }
  107.       Sounds.ambienceInterval = setInterval(Sounds.playAmbience,_loc1_);
  108.    }
  109.    static function stopAmbience()
  110.    {
  111.       clearInterval(Sounds.ambienceInterval);
  112.    }
  113. }
  114.